package jmine.tec.web.wicket.component.iframe;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.util.string.Strings;

/**
 * Componente que representa um iframe na tela.
 * 
 * @author piercio
 */
public class IFrame extends WebMarkupContainer {

    private final String sourceUrl;

    /**
     * Construtor.
     * 
     * @param id o web markup id.
     * @param sourceUrl o src do iframe.
     */
    public IFrame(String id, String sourceUrl) {
        super(id);
        this.sourceUrl = sourceUrl;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onComponentTag(ComponentTag tag) {
        this.checkComponentTag(tag, "iframe");

        if (!StringUtils.isEmpty(this.sourceUrl)) {
            tag.put("src", Strings.replaceAll(this.sourceUrl, "&", "&amp;"));
        }

        super.onComponentTag(tag);
    }
}
